Skip to content

Jiazheng Sun#7

Open
Argun wants to merge 3 commits into
nextopcn:masterfrom
Argun:master
Open

Jiazheng Sun#7
Argun wants to merge 3 commits into
nextopcn:masterfrom
Argun:master

Conversation

@Argun

@Argun Argun commented Mar 26, 2018

Copy link
Copy Markdown

@leonchen83 Practice2最简单的方法公布一下?

@leonchen83

Copy link
Copy Markdown
Contributor
    public Observable<Tuple2<String, Integer>> wordCount1(Observable<String> words) {
    	return words.groupBy(e -> e).flatMap(e -> e.count().toObservable().map(x -> Tuples.of(e.getKey(), x.intValue())));
    }

    public Single<Map<String, Integer>> wordCount2(Observable<String> words) {
        return words.reduce(new HashMap<String, Integer>(), (a, b) -> {
            if (a.containsKey(b)) { a.put(b, a.get(b) + 1); } else { a.put(b, 1); }
            return a;
        });
    }

@leonchen83 leonchen83 changed the title RxJava practice Jiazheng Sun Mar 26, 2018
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants